package com.api.shopapi.mapper;

import com.api.shopapi.entity.JKXueya;
import com.api.shopapi.entity.dto.JKXueyaDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface JKXueyaMapper {

    @Insert("insert into jk_xueya (JKXueyaCode,UserCode,GaoYa,DiYa,XinLv,FromType,InspectTime,CreateTime) values " +
            "(#{jkXueya.JKXueyaCode},#{jkXueya.UserCode},#{jkXueya.GaoYa},#{jkXueya.DiYa},#{jkXueya.XinLv}," +
            "#{jkXueya.FromType},#{jkXueya.InspectTime},#{jkXueya.CreateTime})")
    int insert(@Param("jkXueya") JKXueya jkXueya);
    
    @Update("update jk_xueya set UserCode=#{jkXueya.UserCode},GaoYa=#{jkXueya.GaoYa},DiYa=#{jkXueya.DiYa},XinLv=#{jkXueya.XinLv}," +
            "FromType=#{jkXueya.FromType},InspectTime=#{jkXueya.InspectTime},CreateTime=#{jkXueya.CreateTime} " +
            "where JKXueyaCode=#{jkXueya.JKXueyaCode}")
    int update(@Param("jkXueya") JKXueya jkXueya);


    @Delete("delete from jk_xueya where JKXueyaCode=#{jKXueyaCode}")
    int delete(@Param("jKXueyaCode") String jKXueyaCode);

    @Select("select * from jk_xueya where JKXueyaCode=#{jKXueyaCode} limit 1")
    JKXueya getByJKXueyaCode(@Param("jKXueyaCode") String jKXueyaCode);

    @Select("select * from jk_xueya where UserCode=#{userCode} and InspectTime between #{startTime} and #{endTime} order by InspectTime desc")
    List<JKXueya> getPageList(@Param("userCode") String userCode,@Param("startTime") String startTime,@Param("endTime") String endTime);

    @Select("<script>" +
            "select jx.*,u.Name as userName from jk_xueya jx left join user u on jx.UserCode=u.UserCode " +
            "where u.GovernmentCode=#{governmentCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and u.Name like concat('%',#{name},'%') " +
            "</if>" +
            "and jx.InspectTime between #{startTime} and #{endTime} " +
            "order by jx.InspectTime desc" +
            "</script>")
    List<JKXueyaDTO> getAdmPageList(@Param("name") String name, @Param("governmentCode") String governmentCode, @Param("startTime") String startTime, @Param("endTime") String endTime);


}
